const { execQuery } = require('../utils/db')
const { DB_CONFIG } = require('../config/db')

const queryData = (query) => {
  const sql = `from(bucket: "${DB_CONFIG.bucket}")
              |> range(start: ${query.start}, stop: ${query.stop})
              |> filter(fn: (r) => r["_measurement"] == "${query.measurement}")
              |> filter(fn: (r) => r["_field"] == "${query.field}")
              |> filter(fn: (r) => r["host"] == "${query.host}")`
  return execQuery(sql)
}

module.exports = {
  queryData,
}
